<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        var array = [12,19,9,30,23,17];
        var a = 0;  //内循环次数
        var b = 0;  //外循环次数
        //比较趟数
        for (var i = 0; i < array.length-1; i++) {
//            var cun = true;
            //进行两两比较
            for (var j = 0; j < array.length-1; j++) {
                //进行数值交换 大的靠后 小的往前
                if ( array[j] > array[j+1]) {
                    var temp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = temp;
//                    cun = false;
                }
                a++;
                console.log(array);
            }
//            if (cun) {
//                break;
//            }
            b++;
        }
        console.log("内循环次数为"+a);
        console.log("外循环次数为"+b);
        console.log(array);
    </script>
</head>
<body>

</body>
</html>